#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include "tokenizer.h"
using namespace std;;
#define error(fmt, ...) (fprintf(stderr, "error: " fmt "\n", ##__VA_ARGS__), exit(1))
string filename;
int main(int argc, char** argv) {
	if (argc < 2) error("Please enter the file name.");
	filename = string(argv[1]);
	FILE *file = fopen(argv[1], "r");
	if (!file) error("Unable to open '%s'", argv[1]);
	std::string code;
	char c = fgetc(file);
	while(c != -1) code += c, c = fgetc(file);
	fclose(file);

	auto lines = split(code);
	auto tokenizer = Tokenizer(code, lines, filename);
	for (auto token: tokenizer.list) {
		printf("%d (%d, %d) %s\n", token.type, token.line, token.col, token.value.c_str());
	}
}
